﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Adams.Admin.Business.Security
{
    public class Forgot
    {
        public static DataTransfer.Security.Forgot.PageLoad PageLoad(DataTransfer.Security.Forgot.PageLoadInput input)
        {
            var ret = new DataTransfer.Security.Forgot.PageLoad(); // Create Output Class
            ret.Email = input.Email;
            return ret;
        }

        public static DataTransfer.Security.Forgot.FormOutput TryPasswordReset(DataTransfer.Security.Forgot.FormInput input)
        {
            var ret = new DataTransfer.Security.Forgot.FormOutput(); // Create Output Class

            # region Validate Input
            bool isInputValid = true;

            //// Validate Email
            //if (Shared.Validation.Empty(input.Email, 1, ref ret.EmailValidationCode, ref isInputValid))
            //{
            //    if (Shared.Validation.Size(input.Email, 50, 2, ref ret.EmailValidationCode, ref isInputValid))
            //    {
            //        if (Shared.Validation.RegEx(input.Email, @"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$", 3, ref ret.EmailValidationCode, ref isInputValid))
            //        {

            //        }
            //    }
            //}

            #endregion

            if (isInputValid)
            {
                var data = DataAccess.Security.Forgot.GetUserInfo(input.Email); // Get User Information

                if (data.Exists)
                {
                    // User does exist
                    if (data.IsActive)
                    {
                        Email.QueueEmail("Reset Password", "admin@adamscenter.org", input.Email, "Click here to reset your email", 1);
                        ret.IsValid = true;
                    }
                    else
                    {
                        ret.IsNotActive = true;
                    }
                }
                else
                {
                    ret.DoesNotExist = true;
                }
            }
            else
            {
                // User input invalid
                ret.IsInvalidInput = true;
            }

            return ret;
        }

        public static DataTransfer.Security.Forgot.CompletePageLoad CompletePageLoad(DataTransfer.Security.Forgot.CompletePageLoad input)
        {
            var ret = new DataTransfer.Security.Forgot.CompletePageLoad(); // Create Output Class
            ret.Email = input.Email;
            return ret;
        }
    }
}
